package com.hongyuan.coach.ui.member.view_mode;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.mvvmhabitx.bus.event.SingleLiveEvent;
import com.hongyuan.coach.base.CustomViewModel;
import com.hongyuan.coach.data.Constants;
import com.hongyuan.coach.data.MyRepository;
import com.hongyuan.coach.ui.member.beans.MemberInfoBeans;

public class MemberDetailsViewModel extends CustomViewModel<MyRepository> {

    //用户名的绑定
    public ObservableField<MemberInfoBeans.InfoBean> info = new ObservableField<>();

    public MemberDetailsViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        //通知fragment显示数据
        public SingleLiveEvent<Void> setInfo = new SingleLiveEvent<>();
    }

    //拨打电话
    public BindingCommand callTel = new BindingCommand(() -> {
        getUC().getCallTel().setValue(info.get().getM_mobile());
    });


    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);

        if(code == Constants.MEMBER_INFO){
            MemberInfoBeans infoBeans = (MemberInfoBeans)dataBean;
            info.set(infoBeans.getInfo());
            uc.setInfo.call();
        }

    }
}
